<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:param name="tool"/>
  <xsl:param name="i18n"/>
  <xsl:param name="defaultLanguage" select="'en'"/>

  <xsl:template match="/information-list">
    <xsl:copy>
      <xsl:for-each select="information[@type = $tool]">
        <xsl:if test="not (preceding-sibling::information[identifier = current()/identifier])">
          <xsl:copy>
            <xsl:copy-of select="@type"/>
            <xsl:copy-of select="identifier"/>
            <xsl:copy-of select="version"/>
            <xsl:choose>
              <xsl:when test="description[@internationalization = $i18n]">
                <xsl:copy-of select="description[@internationalization = $i18n][position() = 1]"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:choose>
                  <xsl:when test="description[@internationalization = $defaultLanguage]">
                    <xsl:copy-of select="description[@internationalization = $defaultLanguage][position() = 1]"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <description>
                      <xsl:attribute name="internationalization">
                        <xsl:value-of select="$defaultLanguage"/>
                      </xsl:attribute>
                    </description>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:copy-of select="check-value"/>
            <xsl:copy-of select="option"/>
          </xsl:copy>
        </xsl:if>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
